//
//  GQHContractView.m
//  Xanthium
//
//  Created by GuanQinghao on 12/03/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#import "GQHContractView.h"
#import "GQHHeader.h"
#import "GQHCustomCell.h"

@interface GQHContractView () <UITableViewDelegate,UITableViewDataSource> {
    
    NSArray *textArray;
}

@end

@implementation GQHContractView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        [self loadLocalData];
        [self loadUserInterface];
    }
    return self;
}

#pragma mark --Data
- (void)loadLocalData {
    
    textArray = @[@" ",@"托运",@"承运",@"声明"];
    
}

#pragma mark --View
- (void)loadUserInterface {
    
    CGRect frame = CGRectMake(0, self.qh_statusBarHeight + self.qh_navigationBarHeight, self.qh_contentAreaWidth, self.qh_contentAreaHeight + self.qh_tabBarHeight);
    UITableView *tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = kWhiteColor;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.showsVerticalScrollIndicator = NO;
    if (@available(iOS 11.0, *)) {
        
        tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    [self addSubview:tableView];
}

#pragma mark --Delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (1 == indexPath.section) {
        
        return 500.0f;
    } else if (2 == indexPath.section) {
        
        return 100.0f;
    } else if (3 == indexPath.section) {
        
        return 150.0f;
    } else {
        
        return 50.0f;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *identifier = @"cell";
    GQHOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
#warning
        cell = [[GQHOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    if (0 != section) {
        
        return 60.0f;
    } else {
        
        return CGFLOAT_MIN;
    }
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *headerView = [[UIView alloc] init];
    headerView.backgroundColor = kLightGrayColor;
    
    UILabel *textLabel = [[UILabel alloc] init];
    textLabel.text = textArray[section];
    textLabel.textAlignment = NSTextAlignmentLeft;
    [headerView addSubview:textLabel];
    [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.and.bottom.height.mas_equalTo(headerView);
        make.left.mas_equalTo(headerView).with.offset(20);
        make.right.mas_equalTo(headerView).with.inset(20);
    }];
    
    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return CGFLOAT_MIN;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    return [UIView new];
}

@end
